<template>
  <a-modal :title="title" :width="1040" :visible="visible" :confirmLoading="loading" @ok="()=>{this.visible=false}" @cancel="()=>{this.visible=false}">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="8">
            <a-form-item label="订单编号">
              {{ this.entity.WipOrderNo }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="订单物料">
              {{ this.entity.ProductNo }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="数量">
              {{ this.entity.Quantity }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="计划开始">
              {{ moment(this.entity.ScheduledStartDate).format('YYYY-MM-DD') }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="下发时间">
              {{ this.IssusedTime(this.entity.IssuedTime) }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="执行状态">
              {{ this.StatusName(this.entity.Status) }}
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <s-table ref="tables" size="default" rowKey="Id" :columns="columns" :data="loadData" showPagination="auto">
    </s-table>
  </a-modal>
</template>

<script>
import moment from 'moment'
import { STable } from '@/components'
import MainSvc from '@/api/Exec/StationExecutedSvc'

const columns = [
  { title: '单据号', dataIndex: 'reqId', sorter: false },
  { title: '订单号', dataIndex: 'WipOrderNo', sorter: false },
  { title: '工序号', dataIndex: 'OprSequenceNo', sorter: false },
  { title: '报工类型', dataIndex: 'ProgressType', sorter: false, customRender: (value) => {
      if (value === '0') {
        return '开工'
      } else if (value === '1') {
        return '完工'
      } else {
        return ''
      }
    }
  },
  { title: '合格数量', dataIndex: 'Quantity', sorter: false },
  { title: '产品序列号', dataIndex: 'SerialNo', sorter: false },
  { title: '报工数量', dataIndex: 'Quantity', sorter: false }
]

export default {
  components: {
    STable,
    MainSvc
  },
  data() {
    this.columns = columns
    this.title = ''
    return {
      // create model
      visible: false,
      loading: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: { PlanId: '' },
      entity: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        var _query = Object.assign({}, { ...this.queryParam })
        for (const key in _query) {
          if (moment.isMoment(_query[key])) {
            _query[key] = _query[key].format('YYYY-MM-DD')
          }
        }
        const requestParameters = Object.assign({ sortField: 'OprSequenceNo', sortOrder: 'asc', Search: _query }, parameter)
        console.log('loadData request parameters:', requestParameters)
        return MainSvc.GetPage(requestParameters)
      }
    }
  },
  methods: {
    moment,
    init() {
      this.loading = false
      this.visible = true
    },
    openForm(record, title) {
      this.title = title
      this.entity = record
      this.queryParam.PlanId = record.Id
      this.init()
      this.$refs.tables.refresh()
    },
    ProgressStatusName(value) {
        if (value === '110') {
        return '已接收'
        } else if (value === '120') {
        return '进行中'
        } else if (value === '130') {
        return '已完工'
        } else if (value === '140') {
        return '已删除'
        } else if (value === '150') {
        return '强制关闭'
        } else {
        return value
        }
    },
    StatusName(value) {
        if (value === 0) {
            return '待下发'
        } else if (value === 1) {
            return '执行中'
        } else if (value === 2) {
            return '已完成'
        } else if (value === 3) {
            return '已取消'
        } else if (value === 4) {
            return '挂起'
        } else {
            return value
        }
    },
    IssusedTime(value) {
        if (value !== null) {
        return moment(value).format('YYYY-MM-DD HH:mm:ss')
      } else {
        return ''
      }
    }
  }
}
</script>
